function timechange()
{
	this.distance = 0;
	this.day = 0;
	this.hour = 0;
	this.minute = 0;
	this.second = 0;
}

timechange.prototype.setDistance = function(dis)
{
	this.distance = dis;
};

//根据获取的参数来展现界面天，小时，分，秒的数据
timechange.prototype.showDistance = function()
{
	this.dealDistance();
	
	var showday = document.all("day");
	var showhour = document.all("hour");
	var showminute = document.all("minute");
	var showsecond = document.all("second");
	
	if(typeof(showday) == "object")
	{
		showday.innerHTML = this.day;
	}
	
	if(typeof(showhour) == "object")
	{
		showhour.innerHTML = this.hour;
	}
	
	if(typeof(showminute) == "object")
	{
		showminute.innerHTML = this.minute;
	}
	
	if(typeof(showsecond) == "object")
	{
		showsecond.innerHTML = this.second;
	}
};

//根据获取的参数来展现界面天，小时，分，秒的数据
timechange.prototype.dealDistance = function()
{
	var tempdis = parseInt(this.distance);
 	if(tempdis >= 0)
 	{
 			this.day = parseInt(this.distance/(24*60*60));
 			var tempdata = this.distance%(24*60*60);
 			this.hour = parseInt(tempdata/(3600));
 			var minre = parseInt(tempdata%(3600));
 			this.minute = parseInt(minre/60);
 			this.second = parseInt(minre%60);
 	}
};

//每秒钟处理一次distance
timechange.prototype.minusDistance = function()
{
	if(this.distance > 0)
	{
		this.distance = parseInt(this.distance) - 1;
	}
};

//添加以1秒执行一次的方法
function wakeInterval()
{
	change.showDistance();
	if(change.distance > 0)
	{
		window.setTimeout(wakeInterval,1000);	
	}
	change.minusDistance();
	
}

//自动计算报价信息
function calPriceAndTotal(index)
{


	//目录单价
	var priceobj = document.all("price"+index);
	//折扣后总价
	var amountobj = document.all("amount"+index);
	//正折扣率
	var discountobj = document.all("discount"+index);
	//数量
	var numberobj = document.all("number"+index);
	//折扣后单价
	var unitpriceobj = document.all("unitprice"+index);
	
	
	
	
		var price = priceobj.value;
		var discount = discountobj.value;
		var reg = /(^\d{1,12}$)|(^\d{1,12}\.\d{1,12}$)/;
		
			if(!reg.test(numberobj.value))
			{
				numberobj.value = '';
				
			}else{
			
				numberobj.value = dealMoney(numberobj.value);
			}
			
			if(!reg.test(price))
			{
				priceobj.value = '';
				
			}else{
			
			priceobj.value = dealMoney(priceobj.value);
			}
			
			
			
			if(!reg.test(unitpriceobj.value))
			{
				unitpriceobj.value = '';
				
			}else{
			unitpriceobj.value = dealMoney(unitpriceobj.value);
			}
			
			
			
			if(!reg.test(discount))
			{
				discountobj.value = '';
				
			}else{
			discountobj.value = dealMoney(discountobj.value);
			}
			
			
			
			
			if(!reg.test(amountobj.value))
			{
				amountobj.value = '';
				
			}else{
			amountobj.value = dealMoney(amountobj.value);
			}
			
	if(priceobj != null && discountobj != null)
	{
		
			
			
		
		if(price != '' && discount != '')
		{
		
		
			
			
			
			
			
			
			var unitprice = ((parseFloat(price)*(parseFloat(discount)*0.01))).toFixed(3);
			if(typeof(discountobj) == 'object')
			{
				var temp = new String(unitprice);
				
				//判断计算出来的数据是否是nan
				if(!isNaN(temp))
				{
					
						//不再进行折扣率计算，由供应商统一来计算
						//unitpriceobj.value  = temp;
					
				}
				
				
				if(typeof(amountobj) == 'object' && typeof(numberobj) == 'object')
				{
					
					
					var tempvalue = (parseFloat(unitpriceobj.value)*parseFloat(numberobj.value)).toFixed(3);
					
					
					
					//tempvalue = parseFloat(tempvalue).toFixed(3);
					
					temp = new String(tempvalue);
					//把 计算出来的float型的数据进行转换保留小数点后两位 
					
					if(!isNaN(tempvalue))//判断计算出来的数据是否是nan
					{
						
						//不再对总价进行计算
						//	amountobj.value = temp;
						
					}
				}
			}
		}
	}
	
}

function dealMoney(money){

	if(money != null && money.length > 0){
	
		var tempMoney = money.split(".");
		
		if(tempMoney.length == 1){
		
			return tempMoney[0]+".000";
		}else{
		
			var temp = tempMoney[1];
			
			if(temp.length == 1){
			
				return tempMoney[0]+"."+temp+"00";
			}else if(temp.length == 2){
			
				return tempMoney[0]+"."+temp+"0";
			}else{
			
				return tempMoney[0]+"."+temp.substring(0,3);
			}
		}
	}else{
	
		return "0.000";
	}
}

//定位上传文件的输入位置
function showfiledialog(rowindex)
{
	var file = document.all("file"+rowindex);
	var tempx = window.event.x;
	var tempy = window.event.y;
	var imgw = 50;
	var imgh = 20;
	file.style.top = tempy-window.event.offsetY+document.documentElement.scrollTop;
	file.style.left = tempx-window.event.offsetX+document.documentElement.scrollLeft-12;
}


//删除上传文件
function deleteRow(index)
{
	var root = document.all("fileuploadtable");
	var row = "row"+index ;
	
	var rows = root.rows;
    var deletepos = 0;
    
    
    //寻找到对应的删除行并进行删除
	for(var pos = 0; pos < rows.length; pos++)
	{
		var temprow = rows[pos];
		if(temprow.id == row)
		{
			//在删除行信息以前更新此行一下行的索引
			deletepos = pos;
			for(var index=pos+1; index<rows.length; index++)
			{
				var temprow = rows[index];
				var cells = temprow.cells;
				var cell = cells[0];
				if(typeof(cell) == 'object')
				{
					cell.innerText = index;
			
				}
			}
			root.deleteRow(pos);
			break;
		}
	}
}

/*
当输入文件的信息进行改变后对对应的文件进行签名和加密
*/
function ondatachange(fileobject,index)
{
	//判断文件对象的值是否为空
	if(fileobject.value != null && fileobject.value != "")
	{
		var fileType = fileobject.value.substring(fileobject.value.lastIndexOf(".")+1,fileobject.value.length);
		//判断文件的大小
		var filePath = fileobject.value;    
	      var fileSystem = new ActiveXObject("Scripting.FileSystemObject");       
	      var file = fileSystem.GetFile (filePath);    
	      fileSize = file.Size;
	
		if((fileType == "zip" || fileType == "rar" || fileType == "7z") && fileSize < 1024*1024*30 ){
		//获取对应文件所在的位置
		 var row = document.all("row"+index);
		 
		 var cells = row.cells;
		 var cell = cells[1];
		 
		 //把文件的路径进行截取显示文件的名称
		 cell.innerHTML =  fileobject.value.substring(fileobject.value.lastIndexOf("\\")+1,fileobject.value.lastIndexOf("."));
		 
		 
		 var filename = document.all("filename"+index);
		 
		 //设置文件名称
		 
		 filename.value = fileobject.value.substring(fileobject.value.lastIndexOf("\\")+1,fileobject.length);
		 
		 //隐藏掉上传文件按钮
		 var img = document.all("img"+index);
		 
		 
		 img.style.visibility = "hidden";
		 //把加密的文件信息发到对应的位置
		 
		/*
		 var filecontent  = document.all("filecontent"+index);
		 
		 
		 
		 if(filecontent != null && typeof(filecontent) != "undefined")
		 {
		 	filecontent.value = ContentMi;
		 }
		 
		 */
		 
//		 //把签名了文件的信息保存到对应的位置
//			 var signfile = document.all("signfile"+index);
//			 if(signfile != null)
//			 {
//			 	signfile.value = miWen;
//			 }
		 
		 	fileobject.style.display = "none";
		 
		 }else{
		 
		 	showmess("请上传文件类型为rar、zip文件，且文件大小不能超过30M");
		 }
		 
	}
}

/*
	删除报价信息
*/
function removepricemessage(index)
{
	var pricetable = document.all("pricetable");
	
	if(pricetable != null)
	{
		//获取报价信息有多少行
		var rows = pricetable.rows;
		
		if(rows != null && rows.length >0)
		{
			for(var pos = 0; pos < rows.length; pos++)
			{
				var row = rows[pos];
				//寻找要删除的row
				if(row.id == index)
				{
					//删除对应的报价信息
					pricetable.deleteRow(pos);
					break;
				}
			}
		}
		
		//设置动态头的滚动条的位置
		if(pricetable.rows.length == 0)
		{
			var movediv = document.all("movediv");
			if(movediv != null)
			{
				movediv.scrollLeft = 0;
			}
		}	
	}
	
	
	
}


//设置头和表体同时向同一个方向移动 主要是针对报价信息来说
function setScrollData(obj)
{
	var movediv = document.all("movediv");
	movediv.scrollLeft = obj.scrollLeft;
	 
}

//删除文件信息

function deleteAttFile(attpk,distance){
		if(typeof(distance) != "undefined"){
		
			if(distance <= 0){
			
				showmess("应答已过期、附件不能删除!");
				return;
			}
		}
		
		var dhFile = new dHtmlFile();
		parent.deletefile.att = attpk;
		if(attpk.indexOf('lyan') != -1)
			attpk = attpk.substring(0,attpk.length-4);
		parent.deletefile.dObject = document.getElementById(attpk);
		parent.showHideFun();
   		parent.changeShowMessage("请确认是否删除附件",'yes','delete');

}
function showmess(message){
   parent.showHideFun();
   parent.changeShowMessage(message,'yes','ok');

}

function dHtmlFile(){}


dHtmlFile.prototype.deleteFile = function(attPk){

var fileObj = document.getElementById(attPk);
	var parentNode = fileObj.parentNode;	
	var parentNodeNode = parentNode.parentNode;
	parentNodeNode.removeChild(parentNode);
};

function signMsgVO(fileSystemName, signmsg){
	this.fileSystemName = fileSystemName;
	this.signmsg = signmsg;
}

function randomMsg(){
	this.arrays = new Array(); 
}
//产生一个随机码
randomMsg.prototype.birthRandom = function(filename, filetype,signmsg){
	
	var myDate=new Date();
	//小时
	var hours = myDate.getHours();
	//增加小时为两位数
	if(hours.toString().length == 1){
		hours = "0"+hours;
	}
	var miu = myDate.getMinutes();
	//增加分为两位数
	if(miu.toString().length == 1){
		miu = "0"+miu;
	}
	//秒
	var seonde = myDate.getSeconds();
	//增加秒为两位数
	if(seonde.toString().length == 1){
		seonde = "0"+seonde;
	}
	
	
	var appMsg = ""+hours+miu+seonde;
	
	var fileSystemName = filename+"_"+appMsg+"."+filetype;
	
	if(!this.containMsg(fileSystemName)){
		this.arrays.push(new signMsgVO(fileSystemName,signmsg));
	}
	return appMsg;
}
//判断文件是否存在与加密集合中
randomMsg.prototype.containMsg = function(filename){

	var length = this.arrays.length;
	for(var index=0; index<length; index++){
		if(filename == this.arrays[index].fileSystemName){
			return true;
	}
	}
	return false;
}

//获取签名信息

randomMsg.prototype.getSignMsg = function(filename){
	var length = this.arrays.length;
	for(var index=0; index<length; index++){
		if(filename == this.arrays[index].fileSystemName){
			return this.arrays[index].signmsg;
	}
	}
	return "";
}





